package com.audaque.springboot.foshanupload.druid.util;

import com.alibaba.druid.filter.config.ConfigTools;
import com.audaque.springboot.foshanupload.druid.model.rsp.DruidRsaEncryptRsp;

/**
 * @author zgb
 * @desc ...
 * @date 2023-01-24 02:39:19
 */
public class DruidUtil {
    public static DruidRsaEncryptRsp rsaEncrypt(String plaintext) throws Exception {
        DruidRsaEncryptRsp druidRsaEncryptRsp = new DruidRsaEncryptRsp();

        // 调用 druid 生成私钥、公钥、密文
        //ConfigTools.main(new String[]{plaintext});
        //rsa
        String[] arr = ConfigTools.genKeyPair(512);
        String privateKey = arr[0];
        String publicKey = arr[1];
        String passwordEncrypt = ConfigTools.encrypt(arr[0], plaintext);

        druidRsaEncryptRsp.setPrivateKey(privateKey);
        druidRsaEncryptRsp.setPublicKey(publicKey);
        druidRsaEncryptRsp.setCiphertext(passwordEncrypt);

        return druidRsaEncryptRsp;
    }

}
